//
//  NSString+MD5.m
//  Momo
//
//  Created by More on 15/4/13.
//  Copyright (c) 2015年 Suncco. All rights reserved.
//

#import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h>
//#import "NetworkConfig.h"

@implementation NSString (MD5)

/**
 * md5算法
 */
+ (NSString *)md5From:(NSString *)str isLowerCase:(BOOL)isLowerCase {
    const char *cStr = [str UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5 (cStr, (CC_LONG)strlen(cStr), digest);
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [result appendFormat:@"%02x", digest[i]];
    }
    return isLowerCase ? [result lowercaseString] : [result uppercaseString];
}

+ (NSString *)generateSecretKey {
    NSString *originalKey = [NSString stringWithFormat:@"%@%ld%@", @"23kjlkdfjionaiqwe", (long)[[NSDate date] timeIntervalSince1970], @"1"];
    return [[self md5From:originalKey isLowerCase:YES] substringWithRange:NSMakeRange(0, 26)];
}

@end
